import 'dart:typed_data';
import 'dart:ui' as dartUI;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:throttling/throttling.dart';
import 'package:work_tools/values/color.dart';
import 'package:work_tools/values/font.dart';
import 'package:work_tools/values/text_style.dart';
import 'package:work_tools/widget/sheets/add_whitelist_sheet/add_whitelist_logic.dart';

class AddWhitelistSheet extends StatelessWidget {
  final logic = Get.put(AddWhitelistLogic());
  final state = Get.find<AddWhitelistLogic>().state;

  AddWhitelistSheet({
    Key? key,
    required String redisKey,
    required String redisValue,
  }) : super(key: key) {
    state.redisKey = redisKey;
    state.redisValue = redisValue;
    state.newValue = "";
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Container(
        width: 600,
        height: 500,
        color: Colors.white,
        child: Column(
          children: [
            Container(
              padding: const EdgeInsets.all(20),
              decoration: const BoxDecoration(
                border: Border(
                    bottom: BorderSide(color: Color(0xFFDFDFDD), width: 1)),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    child: TextFormField(
                      focusNode: state.node,
                      onChanged: (value) =>
                          state.newValue = value.toUpperCase(),
                      initialValue: state.newValue,
                      keyboardType: TextInputType.number,
                      inputFormatters: state.inputFormatters,
                      style: TextStyle(fontSize: Font.font14),
                      decoration: InputDecoration(
                        contentPadding: EdgeInsets.zero,
                        border: const OutlineInputBorder(
                            borderSide: BorderSide.none),
                        hintText: "请输入${state.keyZh}",
                        counterText: "",
                        hintStyle: TStyleUtil.sc_4_14(ColorsValue.textGrey),
                      ),
                      maxLength: state.maxLength,
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.only(left: 94),
                    width: 1,
                    height: 26,
                    color: const Color(0xFFDFDFDD),
                  ),
                  const SizedBox(width: 10),
                  SizedBox(
                    width: 200,
                    child: InkWell(
                      onTap: () async {
                        Get.back(result: state.newValue);
                      },
                      child: Text(
                        "保存",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: ColorsValue.blue3, fontSize: Font.font14),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            const Spacer(),
          ],
        ),
      ),
    );
  }

  final thr = Throttling(duration: const Duration(seconds: 5));

  static Future<dynamic> displaySheet(
    BuildContext ctx, {
    required String redisKey,
    required String redisValue,
  }) async {
    return await showModalBottomSheet(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      context: ctx,
      builder: (BuildContext context) {
        return AddWhitelistSheet(
          redisKey: redisKey,
          redisValue: redisValue,
        );
      },
    );
  }
}
